<?php

/**
 * define nuo
 */
define('NUO', 1);

/**
 * set date default time zone
 */
date_default_timezone_set('UTC');

/**
 * define root path, seting path, module path, library path
 */

defined('NUO_ROOT_PATH') or define('NUO_ROOT_PATH', realpath(dirname(dirname(__FILE__))) . '/');
defined('NUO_APP_PATH') or define('NUO_APP_PATH', NUO_ROOT_PATH . 'app/');
defined('NUO_SETTING_PATH') or define('NUO_SETTING_PATH', NUO_ROOT_PATH . 'app/setting/');
defined('NUO_MODULE_PATH') or define('NUO_MODULE_PATH', NUO_ROOT_PATH . 'app/module/');
defined('NUO_LIBRARY_PATH') or define('NUO_LIBRARY_PATH', NUO_ROOT_PATH . 'library/');

set_include_path(implode(PATH_SEPARATOR, array(
    NUO_LIBRARY_PATH,
    NUO_MODULE_PATH,
    get_include_path()
)));

/*
 * load initial settings and define paths.
 */

$initConfig =
include (NUO_SETTING_PATH . 'init.php');

foreach ($initConfig['constants'] as $name => $value)
{
    defined($name) or define($name, $value);
}

foreach ($initConfig['ini_sets'] as $name => $value)
{
    ini_set($name, $value);
}

defined('NUO_TEMP_PATH') or define('NUO_TEMP_PATH', NUO_ROOT_PATH . 'temp/');
defined('NUO_LOG_PATH') or define('NUO_LOG_PATH', NUO_ROOT_PATH . 'temp/log/');
defined('NUO_STATIC_PATH') or define('NUO_STATIC_PATH', NUO_ROOT_PATH . 'static/');
defined('NUO_PUBLIC_PATH') or define('NUO_PUBLIC_PATH', NUO_ROOT_PATH . 'public/');

/**
 * over write key & value
 */

// init Nuo
require_once 'Nuo/Exception.php';
require_once 'Nuo.php';
require_once 'View.php';
require_once 'Request.php';
require_once 'Controller.php';

/**
 * register autoload
 */
spl_autoload_register(array(
    'Nuo',
    '__autoload'
));

/**
 * hack inflect array
 */
if (!function_exists('nuo_inflect_string'))
{
    function nuo_inflect_string($string)
    {
        return str_replace(' ', '', ucwords(str_replace(array(
            '.',
            '-'
        ), ' ', $string)));

    }
}

if (!function_exists('nuo_deflect_string'))
{
    function nuo_deflect_string($string)
    {
        return strtolower(trim(preg_replace('/([a-z0-9])([A-Z])/', '\1-\2', $string), '-. '));
    }

}

/**
 * boot.
 */
if (file_exists($file = NUO_SETTING_PATH . 'database.php'))
{
    require_once 'Zend/Db.php';
    require_once 'Zend/Db/Table.php';

    $dbConfig = (
    include $file);

    $db = Zend_Db::factory($dbConfig['adapter'], $dbConfig['params']);
    Zend_Db_Table_Abstract::setDefaultAdapter($db);
}

Nuo::setKinds(
include NUO_SETTING_PATH . 'kind.php');
